package LeetCode;

public class Code198_rob {
    // dp[i]表示以当前节点为末尾的最多收益
    public int rob(int[] nums) {
        if (nums == null || nums.length == 0){
            return 0;
        }
        int[] dp = new int[nums.length];
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < i - 1; j++) {
                dp[i] = Math.max(dp[i], dp[j]);
            }
            dp[i] += nums[i];
            res = Math.max(res, dp[i]);
        }
        return res;
    }
}
